package com.vm.dao.system;

import java.util.ArrayList;

import java.util.List;

import org.hibernate.Query;

import com.vm.dao.BaseDAOImpl;
import com.vm.entity.Menu;
import com.vm.entity.User;


public class MenuDAOImpl extends BaseDAOImpl<Menu, String> implements IMenu {

	public MenuDAOImpl() {
		setEntityClass(Menu.class);
	}

	public List<Menu> findByParentid(String parentid, User user) {
		String[] menuCd = this.getGrpValues(user.getMenuGrpId());
		if(menuCd == null || menuCd.length<1){
			return null;
		}
		Query query = getSession().getNamedQuery("menuAll");
		query.setParameter("pid", parentid);
		query.setParameterList("psCd", menuCd);
		List<Menu> list = query.list();
		return list;
	}
	public List<Menu> findByParentid(String parentid){
		Object[] params = new Object[] { parentid };
		List<Menu> list = super.findByHql("from Menu where parentid=? order by orders", params);
		return list;
	}
	public List<Menu>  findUrlAll(User user){
		String[] menuCd = this.getGrpValues(user.getMenuGrpId());
		if(menuCd == null || menuCd.length<1){
			return new ArrayList<Menu>();
		}
		Query query = getSession().getNamedQuery("menuUrlAll");
		query.setParameterList("psCd", menuCd);
		List<Menu> list = query.list();
		return list;
	}
	
	public List<Menu> findAllMenu() {
		List<Menu> list = super.findByHql("from Menu", new Object[] {});
		return list;
	}

}
